package com.wootion.cims.module.communitymerchant.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.wootion.cims.dao.*;
import com.wootion.cims.general.utils.GetIp;
import com.wootion.cims.module.communitymerchant.dto.Condition;
import com.wootion.cims.module.communitymerchant.dto.PageQueryMerchant;
import com.wootion.cims.module.communitymerchant.dto.ShopDto;
import com.wootion.cims.module.communitymerchant.excel.ShopExcel;
import com.wootion.cims.module.communitymerchant.model.Shop;
import com.wootion.cims.module.communitymerchant.service.MerchantService;
import com.wootion.cims.module.systemsetting.community.model.SysCommunity;
import com.wootion.cims.module.systemsetting.log.model.SysLog;
import com.wootion.cims.module.systemsetting.polt.model.SysPlot;
import com.wootion.cims.module.systemsetting.user.model.SysUserRole;
import com.wootion.cims.module.systemsetting.user.model.User;
import com.wootion.cims.response.ResponseResult;
import com.wootion.cims.response.ResultCode;
import com.wootion.cims.shiro.utils.ShiroUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @Author: LanQiang
 * @Date: 2023/01/03/15:51
 * @Description: 作用xxx
 */
@Slf4j
@Service
public class MerchantServiceImpl implements MerchantService {
    @Resource
    private ShopDao shopDao;
    @Resource
    private SysUserRoleDao sysUserRoleDao;
    @Resource
    private SysRoleDao sysRoleDao;
    @Resource
    private SysUserCommunityDao sysUserCommunityDao;
    @Value("${cims.path}")
    private String basePath;
    @Resource
    private SysLogDao sysLogDao;
    @Resource
    private SysCommunityDao sysCommunityDao;
    @Resource
    private SysPlotDao sysPlotDao;
    /**
     * 社区商户列表查询
     * @param pageQueryMerchant
     * @return
     */
    @Override
    public ResponseResult list(PageQueryMerchant pageQueryMerchant) {
        Integer page = pageQueryMerchant.getPage();
        Integer limit = pageQueryMerchant.getLimit();
        if(Objects.isNull(page) || Objects.isNull(limit)){
            return ResponseResult.builder().code(ResultCode.SYSTEM_ERROR.getCode()).message("页码数和每页显得的天数不能为空").build();
        }
        Condition condition = pageQueryMerchant.getCondition();
        String category = null;
        String keyWord = null;
        if(!Objects.isNull(condition)){
            category = condition.getCategory();//门店类型
            keyWord = condition.getKeyWord();//关键字
        }
        //获取当前登陆人的信息
        User user = (User) ShiroUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper5 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper5.eq(SysUserRole::getUserId, user.getId());
        SysUserRole sysUserRole = sysUserRoleDao.selectOne(lambdaQueryWrapper5);
        String roleKey = sysRoleDao.findByRoles(sysUserRole.getRoleId());
        //如果是街道管理员
        if ("street:admin".equals(roleKey)) {
            PageDTO<ShopDto> pageDto = new PageDTO<>(page,limit);
            PageDTO<ShopDto> shopDtoPage = shopDao.pageList(pageDto, category, keyWord, null);
            return ResponseResult.builder().data(shopDtoPage).build();
        }
        //如果不是街道管理员
        List<String> communityIds = sysUserCommunityDao.commnityIds(user.getId());
        if (Objects.isNull(communityIds) || communityIds.size() <= 0) {
            return ResponseResult.builder().code(ResultCode.SYSTEM_ERROR.getCode()).message("当前用户还没有任何社区权限").build();
        }
        PageDTO<ShopDto> pageDto = new PageDTO<>(page,limit);
        PageDTO<ShopDto> shopDtoPage = shopDao.pageList(pageDto, category, keyWord, communityIds);
        return ResponseResult.builder().data(shopDtoPage).build();
    }
    /**
     * 新增社区商户
     * @param shopDto
     * @return
     */
    @Override
    public ResponseResult save(ShopDto shopDto) {
        Shop shop = new Shop();
        BeanUtils.copyProperties(shopDto,shop);
        //无id,是新增
        shop.setCreateTime(new Date());
        shop.setEnabled(true);
        int rows = shopDao.insert(shop);
        return rows > 0 ? ResponseResult.builder().build() : ResponseResult.builder().message(ResultCode.SYSTEM_ERROR.getMessage()).code(ResultCode.SYSTEM_ERROR.getCode()).build();
    }
    /**
     * 修改社区商户
     * @param shopDto
     * @return
     */
    @Override
    public ResponseResult update(HttpServletRequest request,ShopDto shopDto) {
        String id = shopDto.getId();
        Shop shop = new Shop();
        BeanUtils.copyProperties(shopDto,shop);
        //有id,是修改
        if(StringUtils.hasText(id)){
            SysLog sysLog = new SysLog();
            sysLog.setIncident("门店信息");
            sysLog.setType("修改");
            sysLog.setValue("业务日志");
            sysLog.setCreateTime(new Date());
            sysLog.setIp(GetIp.getIpAddr(request));
            User user3 = (User) ShiroUtils.getSubject().getPrincipal();
            sysLog.setOperator(user3.getUsername());
            StringBuilder stringBuilder = new StringBuilder("门店名称:");
            String name = shop.getName();
            stringBuilder.append(name);
            sysLog.setContent(stringBuilder.toString());
            //设置修改的详情
            StringBuilder builder = new StringBuilder();
            //基本信息
            Shop oldShop = shopDao.selectById(id);


            shop.setUpdateTime(new Date());
            int rows = shopDao.updateById(shop);
            Shop newShop = shopDao.selectById(id);
            //详细信息
            String baseMsg = baseMsg(oldShop, newShop);
            builder.append(baseMsg);
            String detailedMsg = detailedMsg(newShop.getCategory(), oldShop, newShop);
            builder.append(detailedMsg);
            sysLog.setDetails(builder.toString());

            if(rows>0){
                sysLog.setResult("成功");
            }else {
                sysLog.setResult("失败");
            }
            int insert = sysLogDao.insert(sysLog);
            if(insert>0){
                log.info("门店信息修改日志记录成功");
            }else {
                log.error("门店信息修改日志记录失败");
            }
            return rows > 0 ? ResponseResult.builder().build() : ResponseResult.builder().message(ResultCode.SYSTEM_ERROR.getMessage()).code(ResultCode.SYSTEM_ERROR.getCode()).build();
        }
        return  ResponseResult.builder().message(ResultCode.SYSTEM_ERROR.getMessage()).code(ResultCode.SYSTEM_ERROR.getCode()).build();
    }
    /**
     * 根据id查询当前商户信息
     * @param id
     * @return
     */
    @Override
    public ResponseResult find(String id) {
        LambdaQueryWrapper<Shop> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Shop::getId,id);
        Shop shop = shopDao.selectOne(lambdaQueryWrapper);
        if(!Objects.isNull(shop)){
            return ResponseResult.builder().data(shop).build();
        }
        return ResponseResult.builder().message(ResultCode.SYSTEM_ERROR.getMessage()).code(ResultCode.SYSTEM_ERROR.getCode()).build();
    }
    /**
     * 批量删除商户信息
     * @param shopDto
     * @return
     */
    @Override
    public ResponseResult batchDelete(ShopDto shopDto, HttpServletRequest request) {
        SysLog sysLog = new SysLog();
        sysLog.setIncident("门店信息");
        sysLog.setType("删除");
        sysLog.setValue("业务日志");
        sysLog.setCreateTime(new Date());
        sysLog.setIp(GetIp.getIpAddr(request));
        User user3 = (User) ShiroUtils.getSubject().getPrincipal();
        sysLog.setOperator(user3.getUsername());
        StringBuilder builder = new StringBuilder("门店名称:");
        List<String> ids = shopDto.getIds();
        if(Objects.nonNull(ids) && ids.size()>0){
            for (int i = 0; i < ids.size(); i++) {
                Shop shop = shopDao.selectById(ids.get(i));
                builder.append(shop.getName());
                if(i != (ids.size()-1)){
                    builder.append(",");
                }
            }
        }
        sysLog.setContent(builder.toString());
        int rows = shopDao.updateBatchByIds(shopDto.getIds());
        if(rows>0){
            sysLog.setResult("成功");
        }else {
            sysLog.setResult("失败");
        }
        int insert = sysLogDao.insert(sysLog);
        if (insert > 0) {
            log.info("个人信息修改记录日志成功!!!");
        } else {
            log.error("个人信息修改记录日志失败!!!");
        }
        return rows > 0 ? ResponseResult.builder().build() : ResponseResult.builder().message(ResultCode.SYSTEM_ERROR.getMessage()).code(ResultCode.SYSTEM_ERROR.getCode()).build();
    }
    /**
     * 商户列表excel导出
     * @return
     */
    @Override
    public ResponseResult excelMerchant(ShopExcel shopExcel) {
        //创建一个目录
        File dir = new File(basePath);
        if(!dir.exists()){
            //目录如果不存在就创建一个
            dir.mkdirs();
        }
        String category = null;
        String keyWord = null;
        List<String> ids = null;
        if(!Objects.isNull(shopExcel)){
            category = shopExcel.getCategory();//门店类型
            keyWord = shopExcel.getKeyWord();//关键字
            ids = shopExcel.getIds();//勾选的商户id集合
        }
        //获取当前登陆人的信息
        User user = (User) ShiroUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper5 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper5.eq(SysUserRole::getUserId, user.getId());
        SysUserRole sysUserRole = sysUserRoleDao.selectOne(lambdaQueryWrapper5);
        String roleKey = sysRoleDao.findByRoles(sysUserRole.getRoleId());
        //如果是街道管理员
        List<ShopExcel> shopExcelList = null;
        if ("street:admin".equals(roleKey)) {
            shopExcelList = shopDao.shopExcel(null, ids, category, keyWord);
        }else{
            //如果不是街道管理员
            List<String> communityIds = sysUserCommunityDao.commnityIds(user.getId());
            if (Objects.isNull(communityIds) || communityIds.size() <= 0) {
                return ResponseResult.builder().code(ResultCode.SYSTEM_ERROR.getCode()).message("当前用户还没有任何社区权限").build();
            }
            shopExcelList = shopDao.shopExcel(communityIds,ids,category,keyWord);
        }
        //开始写excel
        try {
            Date date = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
            String format = simpleDateFormat.format(date);
            String filePathName = basePath + format + "商户信息.xlsx";
            if(shopExcelList != null && shopExcelList.size()>0){
                EasyExcel.write(filePathName, ShopExcel.class).sheet("商户信息表").doWrite(shopExcelList);
                return ResponseResult.builder().data(filePathName).build();
            }
            return ResponseResult.builder().build();
        } catch (Exception ex) {
            log.info("写商户信息列表excel时出现异常！");
            log.info(ex.getMessage());
            return ResponseResult.builder().code(ResultCode.SYSTEM_ERROR.getCode()).message("系统读写文件时，出现异常").build();
        }
    }

    public String baseMsg(Shop oldShop ,Shop newShop){
        StringBuilder builder = new StringBuilder();
        //门店类型
        if(StringUtils.hasText(oldShop.getCategory())){
            if(StringUtils.hasText(newShop.getCategory())){
                if(!oldShop.getCategory().equals(newShop.getCategory())){
                    builder.append("门店类型修改前:")
                            .append(oldShop.getCategory())
                            .append(",修改后:")
                            .append(newShop.getCategory())
                            .append("。");
                }
            }else {
                builder.append("门店类型修改前:")
                        .append(oldShop.getCategory())
                        .append(",修改后:无。");
            }
        }else {
            if(StringUtils.hasText(newShop.getCategory())){
                builder.append("门店类型修改前:无")
                        .append(",修改后:")
                        .append(newShop.getCategory())
                        .append("。");
            }
        }
        //所属社区
        if(StringUtils.hasText(oldShop.getCommunityId())){
            if(StringUtils.hasText(newShop.getCommunityId())){
                if(!oldShop.getCommunityId().equals(newShop.getCommunityId())){
                    SysCommunity oldCommunity = sysCommunityDao.selectById(oldShop.getCommunityId());
                    SysCommunity newCommunity = sysCommunityDao.selectById(newShop.getCommunityId());
                    builder.append("所属社区修改前:")
                            .append(oldCommunity.getName())
                            .append(",修改后:")
                            .append(newCommunity.getName())
                            .append("。");
                }
            }else {
                SysCommunity oldCommunity = sysCommunityDao.selectById(oldShop.getCommunityId());
                builder.append("所属社区修改前:")
                        .append(oldCommunity.getName())
                        .append(",修改后:无。");
            }
        }else {
            if(StringUtils.hasText(newShop.getCommunityId())){
                SysCommunity newCommunity = sysCommunityDao.selectById(newShop.getCommunityId());
                builder.append("门店类型修改前:无")
                        .append(",修改后:")
                        .append(newCommunity.getName())
                        .append("。");
            }
        }
        //所属小区
        if(StringUtils.hasText(oldShop.getPlotId())){
            if(StringUtils.hasText(newShop.getPlotId())){
                if(!oldShop.getPlotId().equals(newShop.getPlotId())){
                    SysPlot oldPlot = sysPlotDao.selectById(oldShop.getPlotId());
                    SysPlot newPlot = sysPlotDao.selectById(newShop.getPlotId());
                    builder.append("所属社区修改前:")
                            .append(oldPlot.getName())
                            .append(",修改后:")
                            .append(newPlot.getName())
                            .append("。");
                }
            }else {
                SysPlot oldPlot = sysPlotDao.selectById(oldShop.getPlotId());
                builder.append("所属社区修改前:")
                        .append(oldPlot.getName())
                        .append(",修改后:无。");
            }
        }else {
            if(StringUtils.hasText(newShop.getCommunityId())){
                SysPlot newPlot = sysPlotDao.selectById(newShop.getPlotId());
                builder.append("门店类型修改前:无")
                        .append(",修改后:")
                        .append(newPlot.getName())
                        .append("。");
            }
        }
        //门店名称
        if(StringUtils.hasText(oldShop.getName())){
            if(StringUtils.hasText(newShop.getName())){
                if(!oldShop.getName().equals(newShop.getName())){
                    builder.append("门店名称修改前:")
                            .append(oldShop.getName())
                            .append(",修改后:")
                            .append(newShop.getName())
                            .append("。");
                }
            }else {
                builder.append("门店名称修改前:")
                        .append(oldShop.getName())
                        .append(",修改后:无。");
            }
        }else {
            if(StringUtils.hasText(newShop.getName())){
                builder.append("门店名称修改前:无")
                        .append(",修改后:")
                        .append(newShop.getName())
                        .append("。");
            }
        }
        //组织机构代码
        if(StringUtils.hasText(oldShop.getCodeOrg())){
            if(StringUtils.hasText(newShop.getCodeOrg())){
                if(!oldShop.getCodeOrg().equals(newShop.getCodeOrg())){
                    builder.append("组织机构代码修改前:")
                            .append(oldShop.getCodeOrg())
                            .append(",修改后:")
                            .append(newShop.getCodeOrg())
                            .append("。");
                }
            }else {
                builder.append("组织机构代码修改前:")
                        .append(oldShop.getCodeOrg())
                        .append(",修改后:无。");
            }
        }else {
            if(StringUtils.hasText(newShop.getCodeOrg())){
                builder.append("组织机构代码修改前:无")
                        .append(",修改后:")
                        .append(newShop.getCodeOrg())
                        .append("。");
            }
        }
        //统一社会信用代码
        if(StringUtils.hasText(oldShop.getCodeUni())){
            if(StringUtils.hasText(newShop.getCodeUni())){
                if(!oldShop.getCodeUni().equals(newShop.getCodeUni())){
                    builder.append("统一社会信用代码修改前:")
                            .append(oldShop.getCodeUni())
                            .append(",修改后:")
                            .append(newShop.getCodeUni())
                            .append("。");
                }
            }else {
                builder.append("统一社会信用代码修改前:")
                        .append(oldShop.getCodeUni())
                        .append(",修改后:无。");
            }
        }else {
            if(StringUtils.hasText(newShop.getCodeUni())){
                builder.append("统一社会信用代码修改前:无")
                        .append(",修改后:")
                        .append(newShop.getCodeUni())
                        .append("。");
            }
        }
        //登记注册类型
        if(StringUtils.hasText(oldShop.getTypeBusiness())){
            if(StringUtils.hasText(newShop.getTypeBusiness())){
                if(!oldShop.getTypeBusiness().equals(newShop.getTypeBusiness())){
                    builder.append("登记注册类型修改前:")
                            .append(oldShop.getTypeBusiness())
                            .append(",修改后:")
                            .append(newShop.getTypeBusiness())
                            .append("。");
                }
            }else {
                builder.append("登记注册类型修改前:")
                        .append(oldShop.getTypeBusiness())
                        .append(",修改后:无。");
            }
        }else {
            if(StringUtils.hasText(newShop.getTypeBusiness())){
                builder.append("登记注册类型修改前:无")
                        .append(",修改后:")
                        .append(newShop.getTypeBusiness())
                        .append("。");
            }
        }

        //开业(成立)时间
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        if(Objects.nonNull(oldShop.getTimeOpen())){
            if(Objects.nonNull(newShop.getTimeOpen())){
                if(!oldShop.getTimeOpen().toString().equals(newShop.getTimeOpen().toString())){
                    builder.append("开业时间修改前:")
                            .append(simpleDateFormat.format(oldShop.getTimeOpen()))
                            .append(",修改后:")
                            .append(simpleDateFormat.format(newShop.getTimeOpen()))
                            .append("。");
                }
            }else {
                builder.append("开业时间修改前:")
                        .append(simpleDateFormat.format(oldShop.getTimeOpen()))
                        .append(",修改后:无。");
            }
        }else {
            if(Objects.nonNull(newShop.getTimeOpen())){
                builder.append("开业时间修改前:无")
                        .append(",修改后:")
                        .append(simpleDateFormat.format(newShop.getTimeOpen()))
                        .append("。");
            }
        }

        //营业状态
        if(StringUtils.hasText(oldShop.getStatusOpen())){
            if(StringUtils.hasText(newShop.getStatusOpen())){
                if(!oldShop.getStatusOpen().equals(newShop.getStatusOpen())){
                    builder.append("营业状态修改前:")
                            .append(oldShop.getStatusOpen())
                            .append(",修改后:")
                            .append(newShop.getStatusOpen())
                            .append("。");
                }
            }else {
                builder.append("营业状态修改前:")
                        .append(oldShop.getStatusOpen())
                        .append(",修改后:无。");
            }
        }else {
            if(StringUtils.hasText(newShop.getStatusOpen())){
                builder.append("营业状态修改前:无")
                        .append(",修改后:")
                        .append(newShop.getStatusOpen())
                        .append("。");
            }
        }

        //主要业务活动
        if(StringUtils.hasText(oldShop.getBusinessActivities())){
            if(StringUtils.hasText(newShop.getBusinessActivities())){
                if(!oldShop.getBusinessActivities().equals(newShop.getBusinessActivities())){
                    builder.append("主要业务活动修改前:")
                            .append(oldShop.getBusinessActivities())
                            .append(",修改后:")
                            .append(newShop.getBusinessActivities())
                            .append("。");
                }
            }else {
                builder.append("主要业务活动修改前:")
                        .append(oldShop.getBusinessActivities())
                        .append(",修改后:无。");
            }
        }else {
            if(StringUtils.hasText(newShop.getBusinessActivities())){
                builder.append("主要业务活动修改前:无")
                        .append(",修改后:")
                        .append(newShop.getBusinessActivities())
                        .append("。");
            }
        }

        //从业人员
        if(StringUtils.hasText(oldShop.getMunber())){
            if(StringUtils.hasText(newShop.getMunber())){
                if(!oldShop.getMunber().equals(newShop.getMunber())){
                    builder.append("从业人员修改前:")
                            .append(oldShop.getMunber())
                            .append(",修改后:")
                            .append(newShop.getMunber())
                            .append("。");
                }
            }else {
                builder.append("从业人员修改前:")
                        .append(oldShop.getMunber())
                        .append(",修改后:无。");
            }
        }else {
            if(StringUtils.hasText(newShop.getMunber())){
                builder.append("从业人员修改前:无")
                        .append(",修改后:")
                        .append(newShop.getMunber())
                        .append("。");
            }
        }

        //联系方式
        if(StringUtils.hasText(oldShop.getContact())){
            if(StringUtils.hasText(newShop.getContact())){
                if(!oldShop.getContact().equals(newShop.getContact())){
                    builder.append("联系方式修改前:")
                            .append(oldShop.getContact())
                            .append(",修改后:")
                            .append(newShop.getContact())
                            .append("。");
                }
            }else {
                builder.append("联系方式修改前:")
                        .append(oldShop.getContact())
                        .append(",修改后:无。");
            }
        }else {
            if(StringUtils.hasText(newShop.getContact())){
                builder.append("联系方式修改前:无")
                        .append(",修改后:")
                        .append(newShop.getContact())
                        .append("。");
            }
        }

        //负责人
        if(StringUtils.hasText(oldShop.getResponsiblePerson())){
            if(StringUtils.hasText(newShop.getResponsiblePerson())){
                if(!oldShop.getResponsiblePerson().equals(newShop.getResponsiblePerson())){
                    builder.append("负责人修改前:")
                            .append(oldShop.getResponsiblePerson())
                            .append(",修改后:")
                            .append(newShop.getResponsiblePerson())
                            .append("。");
                }
            }else {
                builder.append("负责人修改前:")
                        .append(oldShop.getResponsiblePerson())
                        .append(",修改后:无。");
            }
        }else {
            if(StringUtils.hasText(newShop.getResponsiblePerson())){
                builder.append("负责人修改前:无")
                        .append(",修改后:")
                        .append(newShop.getResponsiblePerson())
                        .append("。");
            }
        }

        //法定代表人
        if(StringUtils.hasText(oldShop.getLawman())){
            if(StringUtils.hasText(newShop.getLawman())){
                if(!oldShop.getLawman().equals(newShop.getLawman())){
                    builder.append("法定代表人修改前:")
                            .append(oldShop.getLawman())
                            .append(",修改后:")
                            .append(newShop.getLawman())
                            .append("。");
                }
            }else {
                builder.append("法定代表人修改前:")
                        .append(oldShop.getLawman())
                        .append(",修改后:无。");
            }
        }else {
            if(StringUtils.hasText(newShop.getLawman())){
                builder.append("法定代表人修改前:无")
                        .append(",修改后:")
                        .append(newShop.getLawman())
                        .append("。");
            }
        }

        //地址
        if(StringUtils.hasText(oldShop.getAddress())){
            if(StringUtils.hasText(newShop.getAddress())){
                if(!oldShop.getAddress().equals(newShop.getAddress())){
                    builder.append("地址修改前:")
                            .append(oldShop.getAddress())
                            .append(",修改后:")
                            .append(newShop.getAddress())
                            .append("。");
                }
            }else {
                builder.append("地址修改前:")
                        .append(oldShop.getAddress())
                        .append(",修改后:无。");
            }
        }else {
            if(StringUtils.hasText(newShop.getAddress())){
                builder.append("地址修改前:无")
                        .append(",修改后:")
                        .append(newShop.getAddress())
                        .append("。");
            }
        }
        return builder.toString();
    }

    public String detailedMsg(String type,Shop oldShop,Shop newShop){
        StringBuilder builder = new StringBuilder();
        if(type.equals("个体经营户")){
            JSONObject jsonObject = JSON.parseObject(oldShop.getData());
            String remark = (String) jsonObject.get("remark");

            JSONObject jsonObject1 = JSON.parseObject(newShop.getData());
            String remark1 = (String) jsonObject1.get("remark");
            if(StringUtils.hasText(remark)){
                if(StringUtils.hasText(remark1)){
                    if(!remark.equals(remark1)){
                        builder.append("其他备注修改前:")
                                .append(remark)
                                .append(",修改后:")
                                .append(remark1);
                    }
                }else {
                    builder.append("其他备注修改前:")
                            .append(remark)
                            .append(",修改后:无");
                }
            }else {
                if(StringUtils.hasText(remark1)){
                    builder.append("其他备注修改前:无")
                            .append(",修改后:")
                            .append(remark1);
                }
            }
            return builder.toString();
        }else if(type.equals("法人单位")){
            JSONObject jsonObject = JSON.parseObject(oldShop.getData());
            String remark = (String) jsonObject.get("remark");
            String zoningCode = (String) jsonObject.get("zoningCode");
            String enterpriseHolding = (String) jsonObject.get("enterpriseHolding");

            JSONObject jsonObject1 = JSON.parseObject(newShop.getData());
            String remark1 = (String) jsonObject1.get("remark");
            String zoningCode1 = (String) jsonObject1.get("zoningCode");
            String enterpriseHolding1 = (String) jsonObject1.get("enterpriseHolding");

            if(StringUtils.hasText(zoningCode)){
                if(StringUtils.hasText(zoningCode1)){
                    if(!zoningCode.equals(zoningCode1)){
                        builder.append("区划代码修改前:")
                                .append(zoningCode)
                                .append(",修改后:")
                                .append(zoningCode1)
                                .append("。");
                    }
                }else {
                    builder.append("区划代码修改前:")
                            .append(zoningCode)
                            .append(",修改后:无。");
                }
            }else {
                if(StringUtils.hasText(zoningCode1)){
                    builder.append("区划代码修改前:无")
                            .append(",修改后:")
                            .append(zoningCode1)
                            .append("。");
                }
            }


            if(StringUtils.hasText(enterpriseHolding)){
                if(StringUtils.hasText(enterpriseHolding1)){
                    if(!enterpriseHolding.equals(enterpriseHolding1)){
                        builder.append("企业控股情况修改前:")
                                .append(enterpriseHolding)
                                .append(",修改后:")
                                .append(enterpriseHolding1)
                                .append("。");
                    }
                }else {
                    builder.append("企业控股情况修改前:")
                            .append(enterpriseHolding)
                            .append(",修改后:无。");
                }
            }else {
                if(StringUtils.hasText(enterpriseHolding1)){
                    builder.append("企业控股情况修改前:无")
                            .append(",修改后:")
                            .append(enterpriseHolding1)
                            .append("。");
                }
            }

            if(StringUtils.hasText(remark)){
                if(StringUtils.hasText(remark1)){
                    if(!remark.equals(remark1)){
                        builder.append("其他备注修改前:")
                                .append(remark)
                                .append(",修改后:")
                                .append(remark1);
                    }
                }else {
                    builder.append("其他备注修改前:")
                            .append(remark)
                            .append(",修改后:无");
                }
            }else {
                if(StringUtils.hasText(remark1)){
                    builder.append("其他备注修改前:无")
                            .append(",修改后:")
                            .append(remark1);
                }
            }
            return builder.toString();
        }else {//产业活动单位
            JSONObject jsonObject = JSON.parseObject(oldShop.getData());
            String remark = (String) jsonObject.get("remark");
            String unitType = (String) jsonObject.get("unitType");
            String zoningCode = (String) jsonObject.get("zoningCode");
            String statusOfLegalEntity = (String) jsonObject.get("statusOfLegalEntity");
            String detailedNameOfLegalEntity = (String) jsonObject.get("detailedNameOfLegalEntity");
            String detailedAdressOfLegalEntity = (String) jsonObject.get("detailedAdressOfLegalEntity");
            String organizationCodeOfLegalEntity = (String) jsonObject.get("organizationCodeOfLegalEntity");
            String unifiedSocialCreditCodeOfLegalEntity = (String) jsonObject.get("unifiedSocialCreditCodeOfLegalEntity");
            String codeOfAdministrativeDivisionOfLegalEntity = (String) jsonObject.get("codeOfAdministrativeDivisionOfLegalEntity");




            JSONObject jsonObject1 = JSON.parseObject(newShop.getData());
            String remark1 = (String) jsonObject1.get("remark");
            String unitType1 = (String) jsonObject1.get("unitType");
            String zoningCode1 = (String) jsonObject1.get("zoningCode");
            String statusOfLegalEntity1 = (String) jsonObject1.get("statusOfLegalEntity");
            String detailedNameOfLegalEntity1 = (String) jsonObject1.get("detailedNameOfLegalEntity");
            String detailedAdressOfLegalEntity1 = (String) jsonObject1.get("detailedAdressOfLegalEntity");
            String organizationCodeOfLegalEntity1 = (String) jsonObject1.get("organizationCodeOfLegalEntity");
            String unifiedSocialCreditCodeOfLegalEntity1 = (String) jsonObject1.get("unifiedSocialCreditCodeOfLegalEntity");
            String codeOfAdministrativeDivisionOfLegalEntity1 = (String) jsonObject1.get("codeOfAdministrativeDivisionOfLegalEntity");


            if(StringUtils.hasText(unitType)){
                if(StringUtils.hasText(unitType1)){
                    if(!unitType.equals(unitType1)){
                        builder.append("单位类型修改前:")
                                .append(unitType)
                                .append(",修改后:")
                                .append(unitType1)
                                .append("。");
                    }
                }else {
                    builder.append("单位类型修改前:")
                            .append(unitType)
                            .append(",修改后:无。");
                }
            }else {
                if(StringUtils.hasText(unitType1)){
                    builder.append("单位类型修改前:无")
                            .append(",修改后:")
                            .append(unitType1)
                            .append("。");
                }
            }

            if(StringUtils.hasText(zoningCode)){
                if(StringUtils.hasText(zoningCode1)){
                    if(!zoningCode.equals(zoningCode1)){
                        builder.append("区划代码修改前:")
                                .append(zoningCode)
                                .append(",修改后:")
                                .append(zoningCode1)
                                .append("。");
                    }
                }else {
                    builder.append("区划代码修改前:")
                            .append(zoningCode)
                            .append(",修改后:无。");
                }
            }else {
                if(StringUtils.hasText(zoningCode1)){
                    builder.append("区划代码修改前:无")
                            .append(",修改后:")
                            .append(zoningCode1)
                            .append("。");
                }
            }

            if(StringUtils.hasText(statusOfLegalEntity)){
                if(StringUtils.hasText(statusOfLegalEntity1)){
                    if(!statusOfLegalEntity.equals(statusOfLegalEntity1)){
                        builder.append("归属法人单位情况修改前:")
                                .append(statusOfLegalEntity)
                                .append(",修改后:")
                                .append(statusOfLegalEntity1)
                                .append("。");
                    }
                }else {
                    builder.append("归属法人单位情况修改前:")
                            .append(statusOfLegalEntity)
                            .append(",修改后:无。");
                }
            }else {
                if(StringUtils.hasText(statusOfLegalEntity1)){
                    builder.append("归属法人单位情况修改前:无")
                            .append(",修改后:")
                            .append(statusOfLegalEntity1)
                            .append("。");
                }
            }

            if(StringUtils.hasText(organizationCodeOfLegalEntity)){
                if(StringUtils.hasText(organizationCodeOfLegalEntity1)){
                    if(!organizationCodeOfLegalEntity.equals(organizationCodeOfLegalEntity1)){
                        builder.append("法人单位组织机构代码（9位）修改前:")
                                .append(organizationCodeOfLegalEntity)
                                .append(",修改后:")
                                .append(organizationCodeOfLegalEntity1)
                                .append("。");
                    }
                }else {
                    builder.append("法人单位组织机构代码（9位）修改前:")
                            .append(organizationCodeOfLegalEntity)
                            .append(",修改后:无。");
                }
            }else {
                if(StringUtils.hasText(organizationCodeOfLegalEntity1)){
                    builder.append("法人单位组织机构代码（9位）修改前:无")
                            .append(",修改后:")
                            .append(organizationCodeOfLegalEntity1)
                            .append("。");
                }
            }

            if(StringUtils.hasText(unifiedSocialCreditCodeOfLegalEntity)){
                if(StringUtils.hasText(unifiedSocialCreditCodeOfLegalEntity1)){
                    if(!unifiedSocialCreditCodeOfLegalEntity.equals(unifiedSocialCreditCodeOfLegalEntity1)){
                        builder.append("法人单位统一社会信用代码（18位）修改前:")
                                .append(unifiedSocialCreditCodeOfLegalEntity)
                                .append(",修改后:")
                                .append(unifiedSocialCreditCodeOfLegalEntity1)
                                .append("。");
                    }
                }else {
                    builder.append("法人单位统一社会信用代码（18位）修改前:")
                            .append(unifiedSocialCreditCodeOfLegalEntity)
                            .append(",修改后:无。");
                }
            }else {
                if(StringUtils.hasText(unifiedSocialCreditCodeOfLegalEntity1)){
                    builder.append("法人单位统一社会信用代码（18位）修改前:无")
                            .append(",修改后:")
                            .append(unifiedSocialCreditCodeOfLegalEntity1)
                            .append("。");
                }
            }

            if(StringUtils.hasText(codeOfAdministrativeDivisionOfLegalEntity)){
                if(StringUtils.hasText(codeOfAdministrativeDivisionOfLegalEntity1)){
                    if(!codeOfAdministrativeDivisionOfLegalEntity.equals(codeOfAdministrativeDivisionOfLegalEntity1)){
                        builder.append("法人单位行政区划代码修改前:")
                                .append(codeOfAdministrativeDivisionOfLegalEntity)
                                .append(",修改后:")
                                .append(codeOfAdministrativeDivisionOfLegalEntity1)
                                .append("。");
                    }
                }else {
                    builder.append("法人单位行政区划代码修改前:")
                            .append(codeOfAdministrativeDivisionOfLegalEntity)
                            .append(",修改后:无。");
                }
            }else {
                if(StringUtils.hasText(codeOfAdministrativeDivisionOfLegalEntity1)){
                    builder.append("法人单位行政区划代码修改前:无")
                            .append(",修改后:")
                            .append(codeOfAdministrativeDivisionOfLegalEntity1)
                            .append("。");
                }
            }

            if(StringUtils.hasText(detailedNameOfLegalEntity)){
                if(StringUtils.hasText(detailedNameOfLegalEntity1)){
                    if(!detailedNameOfLegalEntity.equals(detailedNameOfLegalEntity1)){
                        builder.append("法人单位详细名称修改前:")
                                .append(detailedNameOfLegalEntity)
                                .append(",修改后:")
                                .append(detailedNameOfLegalEntity1)
                                .append("。");
                    }
                }else {
                    builder.append("法人单位详细名称修改前:")
                            .append(detailedNameOfLegalEntity)
                            .append(",修改后:无。");
                }
            }else {
                if(StringUtils.hasText(detailedNameOfLegalEntity1)){
                    builder.append("法人单位详细名称修改前:无")
                            .append(",修改后:")
                            .append(detailedNameOfLegalEntity1)
                            .append("。");
                }
            }

            if(StringUtils.hasText(detailedAdressOfLegalEntity)){
                if(StringUtils.hasText(detailedAdressOfLegalEntity1)){
                    if(!detailedAdressOfLegalEntity.equals(detailedAdressOfLegalEntity1)){
                        builder.append("法人单位详细地址修改前:")
                                .append(detailedAdressOfLegalEntity)
                                .append(",修改后:")
                                .append(detailedAdressOfLegalEntity1)
                                .append("。");
                    }
                }else {
                    builder.append("法人单位详细地址修改前:")
                            .append(detailedAdressOfLegalEntity)
                            .append(",修改后:无。");
                }
            }else {
                if(StringUtils.hasText(detailedAdressOfLegalEntity1)){
                    builder.append("法人单位详细地址修改前:无")
                            .append(",修改后:")
                            .append(detailedAdressOfLegalEntity1)
                            .append("。");
                }
            }

            if(StringUtils.hasText(remark)){
                if(StringUtils.hasText(remark1)){
                    if(!remark.equals(remark1)){
                        builder.append("其他备注修改前:")
                                .append(remark)
                                .append(",修改后:")
                                .append(remark1);
                    }
                }else {
                    builder.append("其他备注修改前:")
                            .append(remark)
                            .append(",修改后:无");
                }
            }else {
                if(StringUtils.hasText(remark1)){
                    builder.append("其他备注修改前:无")
                            .append(",修改后:")
                            .append(remark1);
                }
            }
            return builder.toString();
        }
    }
}
